package com.gis.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.gis.entity.AvgStationData;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gis.entity.OceanBouyData;
import com.gis.mapper.OceanBouyDataMapper;
import com.gis.service.OceanBouyDataService;

import java.util.ArrayList;
import java.util.List;

@Service
public class OceanBouyDataServiceimpl extends ServiceImpl<OceanBouyDataMapper, OceanBouyData> implements OceanBouyDataService {

    @Override
    public List<OceanBouyData> getFromYearAndMonth(int stationId, int fromYear, int fromMonth, int toYear, int toMonth) {
        LambdaQueryWrapper<OceanBouyData> queryWrapper = new LambdaQueryWrapper<OceanBouyData>()
                .between(OceanBouyData::getYear, fromYear, toYear)
                .eq(OceanBouyData::getStationId, stationId)
                .orderByAsc(OceanBouyData::getYear,OceanBouyData::getMonth);
        List<OceanBouyData> oceanBouyDataList = list(queryWrapper);
        List<OceanBouyData> result = new ArrayList<>();
        for(OceanBouyData oceanBouyData: oceanBouyDataList){
            if(oceanBouyData.getYear()==fromYear && oceanBouyData.getMonth().compareTo(fromMonth)<0){
                continue;
            }
            if(oceanBouyData.getYear()==toYear&&oceanBouyData.getMonth().compareTo(toMonth)>0){
                continue;
            }
            result.add(oceanBouyData);
        }
        return result;
    }
}
